package com.itheima.grow.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

@Component
@Slf4j
public class MyBatisAutoFillConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createdTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "createdBy", ()-> "System", String.class);
        this.strictInsertFill(metaObject, "updatedTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "updatedBy", ()-> "System", String.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updatedTime", Date::new, Date.class);
        this.strictUpdateFill(metaObject, "updatedBy", ()-> "System", String.class);
    }
}
